#include <iostream>
#include <queue>
#include <functional>
using namespace std;

int main()
{
	int n;
	cin >> n;
	priority_queue<int, vector<int>, greater<int>> que;
	for (int i = 0, tmp; i < n; ++i) {
		cin >> tmp;
		que.push(tmp);
	}
	long long ans = 0;
	while (--n) {
		int t1 = que.top();
		que.pop();
		int t2 = que.top();
		que.pop();
		ans += t1 + t2;
		que.push(t1 + t2);
	}
	cout << ans << endl;
	return 0;
}
